package ebuy.com.server.imp;

import ebuy.com.dao.Commoditydao;
import ebuy.com.pojo.Commodity;
import ebuy.com.server.Commodityserver;
import ebuy.com.vo.Commodityvo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
@Service
@Transactional//开启事务
public class Commodityserverimp implements Commodityserver {
    //商品展示的业务层 非常简单
    @Autowired
    private Commoditydao commoditydao;
    @Override
    public List<Commodity> Checkpopularproducts(Integer id) {
        return commoditydao.Checkpopularproducts(id);
    }

    @Override
    public Commodity Queryaccordingtotheidoftheproduct(Integer id) {
        return commoditydao.Queryaccordingtotheidoftheproduct(id);
    }

    @Override
    public List<Commodity> Checkshoppingcart(String loginName) {
        return commoditydao.Checkshoppingcart(loginName);
    }

    @Override
    public Integer Checkthebalanceoftheshoppingcart(String loginName) {
        return commoditydao.Checkthebalanceoftheshoppingcart(loginName);
    }

    @Override
    public List<Commodityvo> Paidmerchandisedisplay(String userName) {
        List<Commodityvo> commodityvoList=new ArrayList<>();
        List<Commodity> checkshoppingcart = commoditydao.Checkshoppingcart(userName);
        for (int i = 0; i <checkshoppingcart.size() ; i++) {
            //进行封装实体类
           Commodityvo commodityvo=new Commodityvo();

            commodityvo.setId(checkshoppingcart.get(i).getShoppingid());
            commodityvo.setProductname(checkshoppingcart.get(i).getCommodityname());
            commodityvo.setPictureoftheproduct(checkshoppingcart.get(i).getCommodityimg());
            commodityvo.setSubtotal(checkshoppingcart.get(i).getPrice()*checkshoppingcart.get(i).getNumberofgoods());
            commodityvo.setPurchasequantity(checkshoppingcart.get(i).getNumberofgoods());

           commodityvoList.add(commodityvo);


        }
        return commodityvoList;
    }

    @Override
    public String Queryaccordingtoshoppingcartid(Integer id) {
        return commoditydao.Queryaccordingtoshoppingcartid(id);
    }

    @Override
    public Integer Checkthepriceoftheproduct(Integer id, String loginName) {
        return commoditydao.Checkthepriceoftheproduct(id, loginName);
    }

}
